import { login, logout, getInfo } from '@/api/login'
import { getToken, setToken, removeToken } from '@/utils/auth'
import Cookies from 'js-cookie'
const user = {
  state: {
    name: '',
    avatar: '',
    roles: []
  },

  mutations: {},

  actions: {
    // 登录
    Login({ commit }, userInfo) {
      const account = userInfo.account.trim()
      return new Promise((resolve, reject) => {
        login(account, userInfo.passwd).then(response => {
          const data = response.body
          Cookies.set('group',data.group)
          Cookies.set('adminName',data.name||'admin')
          Cookies.set('userId',data.userId)
          resolve()
        }).catch(error => {
          reject(error)
        })
      })
    }
  }
}

export default user
